<?php

namespace app\controller;

use app\ResourceModel;
use think\facade\Request;
use app\BaseController;
use app\model\Template as TemplateModel;
use think\facade\Db;

class ShenBeiController extends BaseController
{

    public function getArticle(Request $request)
    {
        $param = $request::param();
        $list = Db::table('article_category')->where('id', 1)->select()->toArray();
        if ($list != false) {
            return $this->returnJson(1001, '返回成功', $list);
        } else {
            return $this->returnJson(1002, '查询失败');

        }
    }

    //获取文章
    public function getArticleList(Request $request)
    {
        $param = $request::param();
        $list1 = Db::table('shenbei_site_management_articles')->where('category_id', 1)->order('sort', 'desc')->limit(7)->select()->toArray();
        $list2 = Db::table('shenbei_site_management_articles')->where('category_id', 2)->order('sort', 'desc')->limit(7)->select()->toArray();
        $list3 = Db::table('shenbei_site_management_articles')->where('category_id', 3)->order('sort', 'desc')->limit(7)->select()->toArray();
        $list4 = Db::table('shenbei_site_management_articles')->where('category_id', 4)->order('sort', 'desc')->limit(7)->select()->toArray();
        return $this->returnJson(1001, '返回成功', ['list1' => $list1, 'list2' => $list2, 'list3' => $list3, 'list4' => $list4]);

    }

    //获取举报内容
    public function getReportContentList(Request $request)
    {
        $param = $request::param();
        $list = Db::table('shenbei_site_report_content')->where('del_flag', 0)->limit(10)->select()->toArray();
        return $this->returnJson(1001, '返回成功', ['list' => $list]);
    }

    //获取项目监督
    public function getProjectSupervisionList(Request $request)
    {
        $param = $request::param();
        $pageSize=$param['pageSize'];
        $data = [];
        if (!empty($param['project_name']) && !empty($param['department'])) {
            $data['project_name'] = $param['project_name'];
            $data['department'] = $param['department'];
        }else if(!empty($param['project_name']) && empty($param['department'])){
            $data['project_name'] = $param['project_name'];
        }else if (empty($param['project_name']) && !empty($param['department'])){
            $data['department'] = $param['department'];
        }
        $rm = new ResourceModel();
        $list = $rm->table('shenbei_site_project_supervision')
            ->where('del_flag', 0)
            ->where($data)
            ->paginate($pageSize)
            ->toArray();
        return $this->returnJson(1001, '返回成功', ['list' => $list]);
    }

//获取项目监督名称列表分页
    public function getSupervisionNameList(Request $request)
    {
        $param = $request::param();
        $list = Db::table('shenbei_site_project_supervision')->where('del_flag', 0)->field('department')->select()->toArray();
        return $this->returnJson(1001, '返回成功', ['list' => $list]);
    }
//公车监督查询列表分页
    public function getBusSupervisionList(Request $request)
    {
        $param = $request::param();
        $pageSize=$param['pageSize'];
        $data = [];
        if (!empty($param['vehicle_user_unit']) && !empty($param['car_number'])) {
            $data['vehicle_user_unit'] = $param['vehicle_user_unit'];
            $data['car_number'] = $param['car_number'];
        }else if(!empty($param['vehicle_user_unit']) && empty($param['car_number'])){
            $data['vehicle_user_unit'] = $param['vehicle_user_unit'];
        }else if (empty($param['vehicle_user_unit']) && !empty($param['car_number'])){
            $data['car_number'] = $param['car_number'];
        }
        $rm = new ResourceModel();
        $list = $rm->table('bus_supervision')
            ->where('del_flag', 0)
            ->where($data)
            ->paginate($pageSize)
            ->toArray();
        return $this->returnJson(1001, '返回成功', ['list' => $list]);
    }

//获取单位名称列表
    public function getCompanyNameList(Request $request)
    {
        $param = $request::param();
        $list = Db::table('bus_supervision')->Distinct(true)->where('del_flag', 0)->field('vehicle_user_unit')->select()->toArray();
        return $this->returnJson(1001, '返回成功', ['list' => $list]);

    }

    //获取区直单位名称
    public function getDistrictNameList(Request $request)
    {
        $param = $request::param();
        $list = Db::table('shenbei_site_district_straight_unit')
            ->where('del_flag', 0)
            ->select()->toArray();
        return $this->returnJson(1001, '返回成功', ['list' => $list]);
    }

    //获取街道单位名称
    public function getStreetNameList(Request $request)
    {
        $param = $request::param();
        $list = Db::table('shenbei_site_street_unit_name')
            ->where('del_flag', 0)
            ->select()->toArray();
        return $this->returnJson(1001, '返回成功', ['list' => $list]);
    }
    //图片展示
    public function getImgList(Request $request)
    {
        $param = $request::param();
        $list = Db::table('home_page_img')
            ->where('del_flag', 0)
            ->select()->toArray();
        return $this->returnJson(1001, '返回成功', ['list' => $list]);
    }
    //添加在线举报信息
    public function addOnlineReport(Request $request)
    {
        $param = $request::param();
        $data['id'] = uniqid();
        $data['report_title']=$param['report_title'];
        $data['report_people_name']=$param['report_people_name'];
        $data['phone']=$param['phone'];
        $data['be_complain_name']=$param['be_complain_name'];
        $data['report_content']=$param['report_content'];
        $data['create_time']=toDate(time());
        $ret = Db::table('shenbei_site_online_reporting')->insert($data);
        if ($ret != false) {
            return $this->returnJson(1001, '保存成功', $param);
        } else {
            return $this->returnJson(1002, '保存失败');
        }

    }

}
